<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="content-type" content="text/html; charset=utf-8" />
		<title>栏目模型</title>
		<link rel="icon" href="favicon.ico" type="image/x-icon" />
		<jsp:include page="../include.jsp" />
		<script>
			$().ready(function() {
				
				$("[href='#']").click(function(){
					
				var $this = $(this);
				var url = $this.attr("url");
				$.dialog({
							type : "warn",
							content : "确定要删除吗?",
							ok : "确 定",
							cancel : "取 消",
							modal : true,
							okCallback : deleteLine
						});
				function deleteLine() {
					$.ajax({
								url : url,
								type : "GET",
								dataType : "json",
								cache : false,
								success : function(data) {
									if (data.status == "success") {
										$this.parent().parent().remove();
									}
									$.message({
												type : data.status,
												content : data.message
											});
								}
							});
					}
				});
				
				$("#saveSingles").click(function() {
					var $idsCheckedCheck = $("#listTable input[name='singles']:checked");
					var url = $(this).attr("url");
					$.ajax({
						url : url,
						data : $idsCheckedCheck.serialize(),
						type : "POST",
						dataType : "json",
						cache : false,
						success : function(data) {
							if (data.status == "success") {
								alert("保存成功");
							}
						}
					});
				});
			});
		</script>
	</head>
	<body class="list">
		<div class="bar">
			<c:choose>
				<c:when test="${model_type==1}">栏目模型</c:when>
				<c:otherwise>内容模型</c:otherwise>
			</c:choose>&nbsp;总记录数: ${fn:length(itemshow)+fn:length(itemhide)}
			<input type="button" class="formButton" onclick="window.history.back(); return false;"
					value="返  回" hidefocus style="float: right; margin-right: 10px"/>
			<input type="button" id="addButton" class="formButton" value="添加"
					hidefocus style="float: right; margin-right: 10px"
						onclick="window.location='beforeAddModelChannel.do?model_id=${model_id}&model_type=${model_type}'" />
		</div>
		<div class="body">
			<div id="table">
				<form id="listForm" action="deleteModelChannel.do" method="post">
					<table id="listTable" class="listTable">
						<tr>
							<th class="check"><input type="checkbox" class="allCheck" /></th>
							<th><a href="#" class="sort" name="field" hidefocus>字段</a></th>
							<th><a href="#" class="sort" name="data_type" hidefocus>数据类型</a></th>
							<th><a href="#" class="sort" name="item_label" hidefocus>名称</a></th>
							<th><a href="#" class="sort" name="priority" hidefocus>排列顺序</a></th>
							<th><a href="#" class="sort" name="is_display" hidefocus>显示</a></th>
							<th><a href="#" class="sort" name="is_single" hidefocus>跨行</a></th>
							<th><span>操作</span></th>
						</tr>
						<c:forEach items="${itemshow}" var="item">
							<tr>
								<td><input type="checkbox" name="ids" value="${item.modelitem_id}" id="id"/></td>
								<td><span title="${item.field}">${item.field} </span></td>
								<td>${item.dataTypeMapping}</td>
								<td>${item.item_label}</td>
								<td>${item.priority}</td>
								<td>是</td>
								<td><input  type="checkbox" name="singles" value="${item.modelitem_id}" id="singles" <c:if test="${item.is_single}">checked="checked"</c:if>/></td>
								<td>
									<a href="editModelChannel.do?id=${item.modelitem_id}" title="修改">[修改]</a>
									<a href="#" url="deleteModelChannel.do?ids=${item.modelitem_id}" title="删除">[删除]</a>
								</td>
							</tr>
						</c:forEach>
					</table>
					<hr/>
					<c:if test="${fn:length(itemhide)!=0}">
						&nbsp;&nbsp;&nbsp;非显示字段:
					</c:if>
					<table id="listTable" class="listTable">
						<tr>
							<th class="check"><input type="checkbox" class="allCheck" /></th>
							<th><a href="#" class="sort" name="field" hidefocus>字段</a></th>
							<th><a href="#" class="sort" name="data_type" hidefocus>数据类型</a></th>
							<th><a href="#" class="sort" name="item_label" hidefocus>名称</a></th>
							<th><a href="#" class="sort" name="priority" hidefocus>排列顺序</a></th>
							<th><a href="#" class="sort" name="is_display" hidefocus>显示</a></th>
							<th><a href="#" class="sort" name="is_single" hidefocus>跨行</a></th>
							<th><span>操作</span></th>
						</tr>
						<c:forEach items="${itemhide}" var="item">
							<tr>
								<td><input type="checkbox" name="ids" value="${item.modelitem_id}" id="id"/></td>
								<td><span title="${item.field}">${item.field} </span></td>
								<td>${item.dataTypeMapping}</td>
								<td>${item.item_label}</td>
								<td>${item.priority}</td>
								<td>否</td>
								<td><input  type="checkbox" name="singles" value="${item.modelitem_id}" id="singles" <c:if test="${item.is_single}">checked="checked"</c:if>/></td>
								<td>
									<a href="editModelChannel.do?id=${item.modelitem_id}" title="修改">[修改]</a>
									<a href="#" url="deleteModelChannel.do?ids=${item.modelitem_id}" title="删除">[删除]</a>
								</td>
							</tr>
						</c:forEach>
					</table>
					<c:choose>
						<c:when test="${fn:length(itemhide)==0&&fn:length(itemshow)==0}">
							<div class="noRecord">没有找到任何记录!</div>
						</c:when>
						<c:otherwise>
							<div class="delete" style="padding-left: 10px"><input
								type="button" id="deleteButton" class="formButton" url="deleteModelChannel.do"
								value="删除" disabled hidefocus />
								<input
								type="button" id="saveSingles" class="formButton" url="save_singles.do"
								value="保存" hidefocus/>
							</div>
						</c:otherwise>
					</c:choose>
				</form>
		   </div>
		</div>
	</body>
</html>